/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.openbookformat.defaultparser;

import java.util.Hashtable;

/**
 *
 * @author MUFEED
 */
public class LatexOptions {
    Hashtable<String, String> page;

    public LatexOptions(String options) {
        page = new Hashtable<String, String>();
        parseOptions(options);
    }

    private void parseOptions(String options){
        String[] lines = options.split("\n");
        for(int i = 0; i < lines.length; i++) {
            //Comments
            if(lines[i].startsWith("%"))
                continue;
            lines[i] = lines[i].trim();
            String section = lines[i].substring(0, lines[i].indexOf("."));
            String key = lines[i].substring(lines[i].indexOf(".") + 1,
                    lines[i].indexOf("=")).trim();
            String val = lines[i].substring(lines[i].indexOf("=") + 1).trim();

            putOptions(section, key, val);
            System.out.println(section + "  .  " + key + "  =  " + val);
        }
    }

    public String getOptions(String section, String key) {
        if (section.equals("page"))
            return page.get(key);
        return null;
    }

    private void putOptions(String section, String key, String val){
        if (section.equals("page")) {
            page.put(key, val);
        }

    }

    public static void main(String[] args) {
        String options =
                "%page options\n" +
                "page.pdfpagewidth = 90mm\n" +
                "page.pdfpageheight = 120mm\n" +
                "page.paperwidth = 90mm\n" +
                "page.paperheight = 120mm\n" +
                "page.textwidth = 70mm\n" +
                "page.textheight = 112mm\n" +
                "page.hoffset = 0pt\n" +
                "page.voffset = 0pt\n" +
                "page.marginparwidth = 0pt\n" +
                "page.marginparsep = 0pt\n" +
                "page.oddsidemargin = -15mm\n" +
                "page.evensidemargin = -15mm\n" +
                "page.topmargin  = 30mm\n" +
                "page.headheight = 0mm\n" +
                "page.headsep = 10mm\n" +
                "page.footskip = 10mm\n";

        LatexOptions lo = new LatexOptions(options);


    }
}
